<template>
    <div class="app-container">
      <Search :crud="crud">
        <el-form-item label="订单号">
            <el-input v-model="query.orderNum" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="下单人">
            <el-input v-model="query.createdName" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="交易开始日期">
            <!-- <el-input v-model="query.createName" placeholder="请输入"></el-input> -->
            <el-date-picker
            v-model="query.createdAutostart"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
          />
        </el-form-item>
        <el-form-item label="交易结束日期">
            <!-- <el-input v-model="query.createName" placeholder="请输入"></el-input> -->
            <el-date-picker
            v-model="query.createdAttend"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
          />
        </el-form-item>
        <el-form-item label="支付方式">
          <el-select v-model="query.payPlatform" placeholder="请选择">
            <el-option
              v-for="item in dict.PAY_METHOD"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="支付状态">
          <el-select v-model="query.payStatus" placeholder="请选择">
            <el-option
              v-for="item in dict.PAY_STATUS"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </Search>
      <el-card>
        <div class="head-container">
            <crudOperation :permission="permission">
                <template slot="right">
                    <!-- <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="handle(null,'new')">新建</el-button> -->
                    <!-- <el-button class="filter-item" size="mini" type="primary" icon="el-icon-delete" @click="handle(null,'batchDelete')">批量删除</el-button> -->
                </template>
            </crudOperation>
        </div>
        <!--表格渲染-->
        <el-table ref="table" border v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
            <el-table-column type="selection" width="55" align="center" fixed="left"/>
            <el-table-column label="序号" type="index" width="50" align="center"/>
            <el-table-column prop="orderNum" label="订单号" align="center" width="120" />
            <el-table-column prop="createdName" label="购买人" align="center" width="120"/>
            <el-table-column prop="orderAmount" label="订单金额" align="center" width="120"/>
            <el-table-column prop="payAmount" label="支付金额" align="center" width="120"/>
            <el-table-column prop="outTradeNo" label="流水号" align="center" show-overflow-tooltip/>
            <el-table-column prop="transactionId" label="交易单号" align="center" show-overflow-tooltip/>
            <el-table-column prop="payAt" label="交易日期" width="120" align="center" show-overflow-tooltip/>
            <el-table-column prop="createdAt" label="创建时间" width="180" align="center"/>
            <el-table-column label="订单状态" align="center" width="100"  fixed="right">
              <template slot-scope="scope" >
                  <span>
                    {{getOrderStatus(scope.row)}}
                  </span>
              </template>
            </el-table-column>
            <el-table-column label="支付状态" align="center" width="100"  fixed="right">
              <template slot-scope="scope" >
                  <span v-if="scope.row.payStatus=='1'" class="payStatus">
                    已支付
                  </span>
                  <span v-else>
                    未支付
                  </span>
              </template>
            </el-table-column>
            <el-table-column label="支付方式" align="center" width="100">
              <template slot-scope="scope" v-if="scope.row.payStatus=='1'">
                  <span v-if="scope.row.payPlatform==1" class="payStatus">
                    微信支付
                  </span>
                  <span v-if="scope.row.payPlatform==2" class="payStatus">
                    支付宝支付
                  </span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="200"  fixed="right">
              <template slot-scope="scope" >
                  <el-button size="mini" @click="logisticsHandle(scope.row,false)">详情</el-button>
                  <el-button size="mini" @click="selectExpressHandle(scope.row)"  v-if="scope.row.orderStatus=='2'">查看物流</el-button>
                  <el-button type="primary" size="mini" @click="logisticsHandle(scope.row, true)" v-if="scope.row.orderStatus=='1' && scope.row.payStatus=='1'">填写物流</el-button>
              </template>
            </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination />
      </el-card>

      <OrderDetailDialog ref="orderDetailDialog" @submitSuccess="submitSuccess"></OrderDetailDialog>
      <LogisticsDetail ref="logisticsDetailRef"></LogisticsDetail>

    </div>
  </template>
  
  <script>
  import crudJob from '@/api/system/job'
  import CRUD, { presenter, header, crud } from '@crud/crud'
  import crudOperation from '@crud/CRUD.operation'
  import pagination from '@crud/Pagination'
  import udOperation from '@crud/UD.operation'
  import Search from '@/components/Search'
  import product from '@/api/product/product'
// import variables from '@/assets/styles/variables.scss'
  import '@/assets/styles/variables.scss'
import OrderDetailDialog from './orderDetailDialog.vue'
import LogisticsDetail from './logisticsDetail.vue'
  export default {
    name: 'BrandIntroductionManage',
    components: { crudOperation, pagination, udOperation, Search, OrderDetailDialog,LogisticsDetail },
    cruds() {
      return CRUD({
        title: '取模演示',
        url: 'tbMallOrdersController/getMallOrdersList',
        requestMethod: 'post',
        sort: ['jobSort,asc', 'id,desc'],
        // takingType:'2',
        otherParams:{'takingType':'2'},
        // params:{'takingType':'2'},
        crudMethod: { ...crudJob }
      })
    },
    // mixins: [presenter()],
    mixins: [presenter(), header(), crud()],
    // 数据字典
    dicts: ['PAY_METHOD','PAY_STATUS'],
    data() {
      return {
        permission: {
          add: ['admin', 'job:add'],
          edit: ['admin', 'job:edit'],
          del: ['admin', 'job:del']
        },
        dataList:[
          
        ], //crud.data
      }
    },
    // computed: {
    //     variables() {
    //         return variables
    //     },
    // },
    methods: {
      // 改变状态
      changeEnabled(data, val) {
        product.tbDemoMoldTakingUpdateStatus({id:data.id,isRelease:val}).then(() => {
          this.$notify({ message: '操作成功', type: 'success'});
          this.crud.refresh();
        }).catch(err => {
          data.isRelease = !data.isRelease
          if (data.isRelease=='1') {
            data.isRelease = '0';
          }else{
            data.isRelease = '1';
          }
        })
      },
      logisticsHandle(row,isLogistics){// 填写物流
        this.$refs.orderDetailDialog.orderId = row.id;
        this.$refs.orderDetailDialog.isShow = true;
        this.$refs.orderDetailDialog.isLogistics = isLogistics;
        this.$refs.orderDetailDialog.getTbMallOrdersById();
      },
      selectExpressHandle(row){// 查看物流
        this.$refs.logisticsDetailRef.isShow = true;
        this.$refs.logisticsDetailRef.selectExpress(row.id);
      },
      // 删除
      deleteHandle(params){
        this.$confirm('确定删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          product.tbDemoMoldTakingDelete(params).then((res) => {
            this.$notify({ message: '操作成功', type: 'success'});
            this.crud.refresh()
          }).catch(() => {})
        })
      },
      // 新建取模成功
      submitSuccess(){
        this.crud.refresh();
      },
      getOrderStatus(value){
        switch (value.orderStatus) {
          case '0':
            return '待付款'
          case '1':
            return '待发货'  
          case '2':
            return '待收货' 
          case '3':
            return '已收货'  
          case '4':
            return '完成'   
          default:
            break;
        }
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  $spinnerColor:#6369D8;
   ::v-deep .el-input-number .el-input__inner {
      text-align: left;
    }

    .item {
      margin-top: 10px;
      margin-right: 10px;
    }
    .payStatus{
        // color:$menuBg
        color: $spinnerColor;
        font-weight: bold;
        
    }
  </style>
  